#include <bits/stdc++.h>

#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }

const int N = 2010;

int n, m, c;
veg G[N];
bool ok = 0;
int dis[N];
bool vis[N];
int fa[13][N], dep[N];

bool isf(int y, int x) {
	per(i, 11, 0) if(dep[fa[i][x]] >= dep[y]) x = fa[i][x];
	return x == y;
}

int id[N];
void solve(int s) {
	priority_queue < pii, vector < pii >, greater < pii > > q;
	rep(i, 1, n) dis[i] = 0x3f3f3f3f, vis[i] = 0;
	dis[s] = 0; q.ep(0, s); fa[0][s] = 0;
	while(q.size()) {
		int x = q.top().se; q.pop(); if(vis[x]) continue;
		vis[x] = true;
		for(auto v : G[x]) {
			int y = v.fi, w = v.se;
			if(dis[y] > dis[x] + w) dis[y] = dis[x] + w, fa[0][y] = x, q.ep(dis[y], y);
		}
	}
	rep(i, 1, n) id[i] = i;
	sort(id + 1, id + n + 1, [&](int x, int y) { return dis[x] < dis[y]; });
	rep(i, 1, n) {
		int x = id[i];
		dep[x] = dep[fa[0][x]] + 1;
	}
	rep(i, 1, 11) {
		rep(j, 1, n) fa[i][j] = fa[i - 1][fa[i - 1][j]];
	}
	int mt = 0x3f3f3f3f;
	rep(x, 1, n) if(vis[x]) for(auto v : G[x]) {
		int y = v.fi, w = v.se;
		if(dep[y] < dep[x] && isf(y, x)) chkmin(mt, dis[x] - dis[y] + w);
	}
	if(mt <= c) ok = 1;
}

int main() {
#ifdef YJR_2333_TEST
	freopen("1.in", "r", stdin);
#endif
	n = in, m = in, c = in;
	bool fl = 0;
	rep(i, 1, m) {
		int u = in, v = in, p = in; fl |= p <= c;
		G[u].eb(v, p);
	} if(!fl) return puts("0"), 0;
	rep(i, 1, n) if(!ok) solve(i);
	if(ok) puts("2");
	else puts("1");
	return 0;
}
